package com.songlanyun.modules.pointconfig.service.impl;

import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.songlanyun.common.utils.DateUtils;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.songlanyun.common.utils.PageUtils;
import com.songlanyun.common.utils.Query;

import com.songlanyun.modules.pointconfig.dao.PointConfigLogDao;
import com.songlanyun.modules.pointconfig.entity.PointConfigLog;
import com.songlanyun.modules.pointconfig.service.PointConfigLogService;


@Service("pointConfigLogService")
public class PointConfigLogServiceImpl extends ServiceImpl<PointConfigLogDao, PointConfigLog> implements PointConfigLogService {

    @Override
    public PointConfigLog create(PointConfigLog entity) {
        this.baseMapper.insert(entity);
        return entity;
    }

    @Override
    public PointConfigLog modify(PointConfigLog entity) {
        return null;
    }

    @Override
    public void remove(Integer id) {

    }

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        LambdaQueryWrapper<PointConfigLog> wrapper = new LambdaQueryWrapper<>();
        Date startTime = MapUtil.getDate(params, "start_time");
        wrapper.ge(ObjectUtil.isNotNull(startTime),PointConfigLog::getCreateTime,startTime);

        Date endTime = MapUtil.getDate(params, "end_time");
        if((ObjectUtil.isNotNull(endTime)))
        {
            endTime = DateUtils.addDateDays(endTime, 1);
            wrapper.le(ObjectUtil.isNotNull(endTime), PointConfigLog::getCreateTime, endTime);
        }

        wrapper.orderByDesc(PointConfigLog::getCreateTime);
        IPage<PointConfigLog> page = this.page(
                new Query<PointConfigLog>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }

}
